<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
    </style>
</head>

<body>
    <script type="module">
        import * as THREE from './js/three.module.js';
        import { OrbitControls } from './js/OrbitControls.js'
        // scene
        var scene = new THREE.Scene();
        // camera
        var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, .1, 1000);
        camera.position.z = 300

        // 创建环境光
        let Light = new THREE.AmbientLight(0xffffff);
        scene.add(Light)
        // 创建点光源
        let Points = new THREE.PointLight(0xffffff);
        Points.position.set(300, 200, 300)
        scene.add(Points)

        // 创建一个立方体
        let Geometry = new THREE.BoxGeometry(100, 100, 100);
        /**
         * 创建纹理贴图
         */
        let textureLoader = new THREE.TextureLoader()
        let cube
        textureLoader.load('./img/wallhaven.jpg', (texture) => {
            let Material = new THREE.MeshLambertMaterial({
                map: texture //map 颜色贴图 默认为null
            }); //创建材质
            let materialMesh = new THREE.Mesh(
                Geometry,
                Material
            )
            scene.add(materialMesh)
            cube = materialMesh
            render()
        })

        // renderer
        let renderer = new THREE.WebGLRenderer({ antialias: true });
        renderer.setSize(window.innerWidth, window.innerHeight);
        document.body.appendChild(renderer.domElement);
        function render() {
          requestAnimationFrame( render )
            cube.rotation.x += 0.01;
            cube.rotation.y += 0.01;
            renderer.render(scene, camera);
        }
        const Controls = new OrbitControls(camera, renderer.domElement)
        Controls.target.set(0, 0, -0.2)
        Controls.update()
    </script>
</body>

</html>